<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 400px;
            border-bottom: 1px solid #ccc ;
            margin:  100px auto;
            position: relative;
        }
        .box input{
                width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }
        .box img{
            width: 24px;
            position: absolute;
            right: 30px;
            top: 10px;
        }

    </style>
</head>
<body>
    <div class="box">
        <!-- 这里插入闭眼图片  id="eye"-->
        <label for=""></label>
        <input type="password" id="pwd" >
    </div>
    <script>
        //1.获取元素
        var eye=document.getElementById("eye");
        var pwd=document.getElementById("pwd");
        //2.注册事件 处理程序
        var flag=0;
        eye.onclick=function(){
            //点击一次之后,flag一定要变化
            if(flag==0){
                pwd.type='text';
                // 改图片
                flag=1;
            }else{
                pwd.type="password";
                //改图片
                flag=0;
            }
            
        }
    </script>
</body>
</html>